Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-2-csv

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-2-csv

A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.

  • 3.20.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
440K
increased by1.49%
Maintainers
1
Weekly downloads
 
Created

What is json-2-csv?

The json-2-csv npm package is a utility for converting JSON data to CSV format and vice versa. It is useful for data transformation tasks, especially when dealing with data interchange between systems that use different formats.

What are json-2-csv's main functionalities?

Convert JSON to CSV

This feature allows you to convert an array of JSON objects into a CSV string. The code sample demonstrates how to use the json2csv function to transform JSON data into CSV format.

const json2csv = require('json-2-csv');

const json = [
  { name: 'John', age: 30, city: 'New York' },
  { name: 'Anna', age: 22, city: 'London' },
  { name: 'Mike', age: 32, city: 'Chicago' }
];

json2csv.json2csv(json, (err, csv) => {
  if (err) {
    throw err;
  }
  console.log(csv);
});

Convert CSV to JSON

This feature allows you to convert a CSV string into an array of JSON objects. The code sample demonstrates how to use the csv2json function to transform CSV data into JSON format.

const json2csv = require('json-2-csv');

const csv = 'name,age,city\nJohn,30,New York\nAnna,22,London\nMike,32,Chicago';

json2csv.csv2json(csv, (err, json) => {
  if (err) {
    throw err;
  }
  console.log(json);
});

Custom Delimiters

This feature allows you to specify custom delimiters for fields and arrays when converting JSON to CSV. The code sample demonstrates how to use the json2csv function with custom delimiter options.

const json2csv = require('json-2-csv');

const json = [
  { name: 'John', age: 30, city: 'New York' },
  { name: 'Anna', age: 22, city: 'London' },
  { name: 'Mike', age: 32, city: 'Chicago' }
];

const options = {
  delimiter: {
    field: ';',
    array: '|'
  }
};

json2csv.json2csv(json, (err, csv) => {
  if (err) {
    throw err;
  }
  console.log(csv);
}, options);

Other packages similar to json-2-csv

Keywords

FAQs

Package last updated on 02 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc